package com.ruoyi.iptv.live.info.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.iptv.live.info.domain.IptvLiveInfo;
import com.ruoyi.iptv.live.info.service.IIptvLiveInfoService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 直播频道Controller
 * 
 * @author 玉念聿辉
 * @date 2021-10-20
 */
@Controller
@RequestMapping("/live/info")
public class IptvLiveInfoController extends BaseController
{
    private String prefix = "live/info";

    @Autowired
    private IIptvLiveInfoService iptvLiveInfoService;

    @RequiresPermissions("live:info:view")
    @GetMapping()
    public String info()
    {
        return prefix + "/info";
    }

    /**
     * 查询直播频道列表
     */
    @RequiresPermissions("live:info:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(IptvLiveInfo iptvLiveInfo)
    {
        startPage();
        List<IptvLiveInfo> list = iptvLiveInfoService.selectIptvLiveInfoList(iptvLiveInfo);
        return getDataTable(list);
    }

    /**
     * 导出直播频道列表
     */
    @RequiresPermissions("live:info:export")
    @Log(title = "直播频道", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(IptvLiveInfo iptvLiveInfo)
    {
        List<IptvLiveInfo> list = iptvLiveInfoService.selectIptvLiveInfoList(iptvLiveInfo);
        ExcelUtil<IptvLiveInfo> util = new ExcelUtil<IptvLiveInfo>(IptvLiveInfo.class);
        return util.exportExcel(list, "直播频道数据");
    }

    /**
     * 新增直播频道
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存直播频道
     */
    @RequiresPermissions("live:info:add")
    @Log(title = "直播频道", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(IptvLiveInfo iptvLiveInfo)
    {
        return toAjax(iptvLiveInfoService.insertIptvLiveInfo(iptvLiveInfo));
    }

    /**
     * 修改直播频道
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        IptvLiveInfo iptvLiveInfo = iptvLiveInfoService.selectIptvLiveInfoById(id);
        mmap.put("iptvLiveInfo", iptvLiveInfo);
        return prefix + "/edit";
    }

    /**
     * 修改保存直播频道
     */
    @RequiresPermissions("live:info:edit")
    @Log(title = "直播频道", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(IptvLiveInfo iptvLiveInfo)
    {
        return toAjax(iptvLiveInfoService.updateIptvLiveInfo(iptvLiveInfo));
    }

    /**
     * 删除直播频道
     */
    @RequiresPermissions("live:info:remove")
    @Log(title = "直播频道", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(iptvLiveInfoService.deleteIptvLiveInfoByIds(ids));
    }
}
